package com.peak.distribution.web.validator;

import java.util.Map;

import com.google.common.collect.Maps;

public class ValidatorFactory {
	
	private Map<Class<? extends ValidateRuleMethod>, ValidateRuleMethod> methodMap = Maps.newHashMap();
	
	public Map<Class<? extends ValidateRuleMethod>, ValidateRuleMethod> getMethodMap() {
		return methodMap;
	}

	public Validator getValidator() {
		return new Validator();
	}
	
	public ValidatorFactory addMethod(Class<? extends ValidateRuleMethod> methodClass) {
		Object methodBean = methodMap.get(methodClass);
		if (methodBean == null) {
			try {
				methodMap.put(methodClass, methodClass.newInstance());
			} catch (Exception e) {
				throw new RuntimeException(methodClass.getName() + "创建对象失败", e);
			}
		}
		return this;
	}
}
